//
//  RxImagePickerDelegateProxy.swift
//  HinsLive
//
//  Created by haoxian on 2019/4/22.
//  Copyright © 2019 Hins. All rights reserved.
//

import UIKit
import RxSwift
import RxCocoa

typealias ImagePickerDelegate = UIImagePickerControllerDelegate & UINavigationControllerDelegate

class RxImagePickerDelegateProxy: DelegateProxy<UIImagePickerController, ImagePickerDelegate>,
                                  DelegateProxyType,
                                  ImagePickerDelegate {
    
    weak private(set) var imagePicker: UIImagePickerController?

    init(imagePicker: ParentObject) {
        self.imagePicker = imagePicker
        super.init(parentObject: imagePicker, delegateProxy: RxImagePickerDelegateProxy.self)
    }
    
    static func registerKnownImplementations() {
        self.register { RxImagePickerDelegateProxy(imagePicker: $0) }
    }
    
    static func currentDelegate(for object: UIImagePickerController) -> ImagePickerDelegate? {
        return object.delegate
    }
    
    static func setCurrentDelegate(_ delegate: ImagePickerDelegate?, to object: UIImagePickerController) {
        object.delegate = delegate
    }
}

